package src.main.java;

import java.io.*;
import java.util.Scanner;

public class Copy {
    /**
     * 拷贝文件
     * @param fileSite
     * @param fileSite2
     */
    public void copy(String fileSite,String fileSite2) {
        FileInputStream fi = null;
        FileOutputStream fo=null;
        try {
            fi = new FileInputStream(fileSite);
            fo=new FileOutputStream(fileSite2);
            int a=0;
            while ((a=fi.read()) !=-1){
                fo.write(a);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e){
            e.printStackTrace();
        }finally {
            if (fi !=null){
                try {
                    fi.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }

    /**
     * 追加
     * @param fileSite
     */
    public void superaddition(String fileSite){
        Scanner scan=new Scanner(System.in);
        String str=scan.next();
        FileWriter fw=null;
        try {
            fw=new FileWriter(fileSite,true);
            fw.append(str);
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if (fw !=null){
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args) {
        Copy co=new Copy();
        co.copy("D:/Typro快捷键常用操作.md","D:/copy.txt");
        co.superaddition("D:/copy.txt");
    }
}
